<?php
/**
 * Class descript.
 * User: chan
 * Date: 2017/10/26 15:29
 */
namespace app\api\controller;
use think\Db;

class Notice extends Base
{
    /**
     * 获取公告列表
     */
    public function getNotice()
    {
        $status = input('status');
        $uid = input('uid');
        if(!empty($status)){
            $where['status'] = $status;
        }else{
            $where ='';
        }

        $data = db('show')->where('type',5)->select();
        foreach ($data as $key => $value) {

            $du = db('notice')->where('notice_id',$value['id'])->where('uid',$uid)->find();

            if($du){

                $data[$key]['is_already'] = 1;
            }else{
                $data[$key]['is_already'] = 0;
            }


        }
        return $this->ajaxReturn($data);
    }

    //更改公告已读状态
    public function editNotice(){
        
        $up['status'] = 1;

        $up['notice_id'] = input('id');

        $up['time'] = time();

        $up['uid'] = input('uid');

        $data = db('show')->where('id',$up['notice_id'])->find();

        $du = db('notice')->where('notice_id',$up['notice_id'])->where('uid',$up['uid'])->find();

        if(!$du){
            $res = db('notice')->insert($up);
        }

        return $this->ajaxReturn($data);

    }

}